using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcCheckTargetDistance : AIConditionBaseNode
    {
        public BBParameter<TargetType> targetType = TargetType.CurrentLockTarget;
        public BBParameter<CompareType> compareType = CompareType.Less;
        public BBParameter<float> compareDistance = 10;
        // 是否使用targetDistance来快速判断距离（需要和NpcUpdateTargetDistance节点搭配使用）
        public BBParameter<bool> fast = false;

        protected override bool OnCheck()
        {
            float distance = 0;
            if (fast.value)
            {
                distance = _entity.battleAgent.targetDistance;
            }
            else
            {
                AIEntity target = _entity.battleAgent.GetTarget(targetType.value);
                distance = Vector3.Distance(target.battleAgent.transform.position, _entity.battleAgent.transform.position);
            }

            bool result = false;
            switch (compareType.value)
            {
                case CompareType.Equal:
                    result = distance == compareDistance.value;
                    break;
                case CompareType.Greater:
                    result = distance > compareDistance.value;
                    break;
                case CompareType.Less:
                    result = distance < compareDistance.value;
                    break;
                case CompareType.GreaterEqual:
                    result = distance >= compareDistance.value;
                    break;
                case CompareType.LessEqual:
                    result = distance <= compareDistance.value;
                    break;
                case CompareType.NotEqual:
                    result = distance != compareDistance.value;
                    break;
            }
            return result;
        }
    }
}